package zz.app.yzjproject

import android.app.Fragment
import android.os.Build
import android.os.Bundle
import android.os.Vibrator
import android.support.annotation.RequiresApi
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import org.w3c.dom.Text

/**
 * 由作者 zzq 于 2017/9/12 22:37 创建
 */
class DebugFragment:Fragment() {
    var tvTime: TextView?=null
    var tvMPU6050ax: TextView?=null
    var tvMPU6050ay: TextView?=null
    var tvMPU6050az: TextView?=null
    var tvMPU6050gx: TextView?=null
    var tvMPU6050gy: TextView?=null
    var tvMPU6050gz: TextView?=null
    var tvMPU6050temp: TextView?=null
    var btnCali: Button?=null
    var tvDegreeKalman:TextView?=null
    var tvDegreeOrig:TextView?=null
    var linechartview:DegreeLineChartView?=null
    var mContext:MainActivity?=null
    @RequiresApi(Build.VERSION_CODES.M)
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?):View {
        val view=inflater.inflate(R.layout.debug_layout, container, false)
        mContext=context as MainActivity
        tvTime=view.findViewById(R.id.tvTime)
        tvMPU6050ax=view.findViewById(R.id.tvMPU6050ax)
        tvMPU6050ay=view.findViewById(R.id.tvMPU6050ay)
        tvMPU6050az=view.findViewById(R.id.tvMPU6050az)
        tvMPU6050gx=view.findViewById(R.id.tvMPU6050gx)
        tvMPU6050gy=view.findViewById(R.id.tvMPU6050gy)
        tvMPU6050gz=view.findViewById(R.id.tvMPU6050gz)
        tvMPU6050temp=view.findViewById(R.id.tvMPU6050temp)
        btnCali=view.findViewById(R.id.btnCali)
        tvDegreeOrig=view.findViewById(R.id.tvDegreeOrig)
        tvDegreeKalman=view.findViewById(R.id.tvDegreeKalman)
        linechartview=view.findViewById(R.id.linechartView)
        btnCali?.setOnClickListener{
            mContext?.mVibrator?.vibrate(500)
            Toast.makeText(mContext,"请保持固定姿势维持2秒",Toast.LENGTH_SHORT).show()
            mContext?.mHandler?.obtainMessage(HandlerMSG.MSG_SENDCOMMAND,ServerCommand.cali())?.sendToTarget()
        }
        return view
    }
}